package com.talkology.pilot.student.controller;

import com.talkology.pilot.database.model.CreditManager;
import com.talkology.pilot.student.service.ICreditManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping(value = "/creditManager")
public class CreditManagerController {
    @Autowired
    private ICreditManagerService service;


    @RequestMapping(value = "/all", method= RequestMethod.GET)
    @ResponseBody
    public List<CreditManager> getCreditByFilter() {
        return service.getAll();
    }

    @RequestMapping(value = "/info", method= RequestMethod.GET)
    @ResponseBody
    public CreditManager getInfo(Integer index) {
        return service.getInfo(index);
    }

    @RequestMapping(value = "/selectByStudentId", method= RequestMethod.GET)
    @ResponseBody
    public CreditManager selectByStudentId(String studentId) {
        return service.selectByStudentId(studentId);
    }

    @RequestMapping(value = "/add", method= RequestMethod.PUT)
    @ResponseBody
    public void add(@RequestBody CreditManager record) {
        service.add(record);
    }

    @RequestMapping(value = "/update", method= RequestMethod.PUT)
    @ResponseBody
    public void update(@RequestBody CreditManager record) {
        service.edit(record);
    }

    @RequestMapping(value = "/delete", method= RequestMethod.DELETE)
    @ResponseBody
    public void delete(@RequestParam(value = "index", required = false) Integer index) {
        service.delete(index);
    }

    @RequestMapping(value = "/changeCredit", method= RequestMethod.POST)
    @ResponseBody
    public void changeCredit(@RequestParam(value = "studentId", required = true) String studentId,
                             @RequestParam(value = "credit", required = true) Double credit) {
        service.changeCredit(studentId, credit);
    }
}
